﻿//********************************************************************************//
//创建日期：<创建日期，2016-03-30>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：地下水打印账单
//********************************************************************************//
layui.use(['layer', 'form', 'element', 'table', 'jquery'], function () {
    var layer = layui.layer
    , form = layui.form
    , element = layui.element
    , table = layui.table
    , $ = layui.jquery;

    var table1 = table.render({
        elem: "#ContentList1",
        url: "",
        width:947,
        height: 'full-130',
        page: false,
        id: 'table1',
        cols: [[
            { checkbox: true, fixed: "left",width:40 }
            , { title: '确认', width: 60, align: 'center',templet: '#eQRZT' }
            , { field: 'S_YONGHUH', title: '用户号',sort:true, width: 90, align: 'center' }
             , { field: 'S_YONGHUM', title: '用户名',width:300, align: 'left'}
              , { field: 'I_YM', title: '水量年月', width: 90, align: 'center' }
              , { field: 'I_SYL', title: '实用量', width: 80, align: 'center' }
              , { field: 'I_SYJH', title: '实用计划', width: 90, align: 'center' }
              , { field: 'I_JJL', title: '加价量', width: 80, align: 'center' }
              , { width: 90, fixed: "right", align: 'center', toolbar: '#eBar1' }
        ]]
    });
    load1();
    /*initial*/
    function initinfo() {
      
    }
    /*end initial*/

    /*event*/
    $("#oSearch").click(function () {
        load1();
    });
    //监听工具条
    table.on('tool(table1)', function (obj) {
        var data = obj.data;
        if (obj.event === 'qfxx') {
            var yhh = data.S_YONGHUH;
            var yhm = data.S_YONGHUM;
            //获取欠费信息html
            $.ajax({
                type: "post",
                cache: false,
                async: false,
                url: "/ashx/LH/LaiHan.ashx",
                data: {
                    "op": "QFXXLISTHTML",
                    "yhh": yhh
                },
                dataType: "html",
                success: function (res) {
                    layer.open({
                        type: 1,
                        title:yhh+"("+yhm+")  近两年加价收费信息",
                        closeBtn: 0,
                        area: ['800px','400px'],
                        shadeClose: true,
                        //skin: 'yourclass',
                        content: "<div style='height:5px'>&nbsp;</div>"+res
                    });
                },
                error: function (error) {
                    layer.msg(error.responseText);
                }
            });
        } 
    });

    $("#oQR").click(function () {
        var checks = table.checkStatus('table1');
        if (checks.data.length == 0) {
            layer.alert("请勾选要确认的项");
            return;
        }
        //get selected items id
        var bhsArr = new Array();
        var val1Arr = new Array();
        for (var i = 0; i < checks.data.length; i++) {
            if (checks.data[i].I_SHIFOUQR != 1) {
                bhsArr.push(checks.data[i].S_YONGHUH);
                val1Arr.push(checks.data[i].I_JJL);
            }
        }
        if (bhsArr.length==0)
        {
            layer.msg("您选择的项均已确认.无需操作.");
            return;
        }
        //update server
        $.ajax({
            type: "post",
            cache: false,
            //async: false,
            url: "/ashx/LH/LaiHan.ashx",
            data: {
                "op": "YUETIAOZQR",
                "yhhs": bhsArr.join(","),
                "jjls": val1Arr.join(",")
            },
            dataType: "json",
            success: function (rs) {
                if (rs.State) {
                    for (var i = 0; i < bhsArr.length; i++) {
                        checks.data[i].I_SHIFOUQR = 1;
                    }
                }
                layer.alert(rs.Msg, function (index) {
                    layer.close(index);
                    table1.reload();
                });
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
    });
    $("#oQXQR").click(function () {
        var checks = table.checkStatus('table1');
        if (checks.data.length == 0) {
            layer.alert("请勾选要取消的项");
            return;
        }
        //get selected items id
        var bhsArr = new Array();
        for (var i = 0; i < checks.data.length; i++) {
            if (checks.data[i].I_SHIFOUQR == 1) {
                bhsArr.push(checks.data[i].S_YONGHUH);
            }
        }
        if (bhsArr.length == 0) {
            layer.msg("请选择已确认的项.");
            return;
        }
        //update server
        $.ajax({
            type: "post",
            cache: false,
            //async: false,
            url: "/ashx/LH/LaiHan.ashx",
            data: {
                "op": "YUETIAOZQRQX",
                "yhhs": bhsArr.join(",")
            },
            dataType: "json",
            success: function (rs) {
                if (rs.State) {
                    for (var i = 0; i < bhsArr.length; i++) {
                            checks.data[i].I_SHIFOUQR = 0;
                    }
                }
                layer.alert(rs.Msg, function (index) {
                    layer.close(index);
                    table1.reload();
                });
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
    });

    
    /*event end*/

    /*list*/    
   

    function load1() {
        table1.reload({
            url: "/ashx/LH/LaiHan.ashx",
            where: {
                "op": "YUETIAOZQRXXHQ",
                "yhh": $("#cYHH").val()
            },
            done: function (res, curr, count) {
                $("#lsCount").text(count);
                var countT = 0;
                for (var i = 0; i < res.data.length; i++) {
                    if (res.data[i].I_SHIFOUQR == 1)
                    {
                        countT++;
                    }
                }
                $("#lsQRCount").text(countT);
            }
        });
    }
    /*end list*/

    /*logic*/

    /*logic end*/

});